cd "C:\Users\ot3\Documents\CRFertility\BirthData"
use 36603-0001-Data, clear //from ICPSR

*widdle sample
keep if YEAR>=1955& YEAR<=1975
keep YEAR STATEFIP STATENAME RACE COFIPS V_H_ID_00_90  V_H_COUNTYCODE BIRTHS_RES  ATTHOSPITAL_RES POPF_FIXED POP_FIXED IM_RES_FIXED V_H_HORANCONAME V_H_COUNTYCODE
drop if RACE==0 
drop if COFIPS==. | POPF==.

drop if inlist(STATEFIP, 2,15) //AK & HI
g south=inlist(STATEFIP, 1, 5, 12, 13,  22, 28, 37, 45, 47, 48, 51)

*Restrict to counties with race-specific births observed in both 1964 and 1969. Main effect of this is dropping counties with small non-white populations.
g tmpobserved6469=(YEAR==1964 | YEAR==1969) & BIRTHS_RES!=.
bysort COFIPS: egen tmpcnt=total(tmpobserved6469)
keep if tmpcnt==4
drop tmpcnt tmpobserved6469


*drop coutnies with more than 1% of pop non-black minority
merge m:1 COFIPS using pctother
drop if _merge==2
drop if pctother>.01
drop _merge pctother

preserve
use 02896-0041-Data, clear
keep if level==1
g pctother=othraces/ totpop
keep fips pctother
rename fips COFIPS
duplicates drop COFIPS, force
save pctother, replace
restore

*create variables, rename for compatability 
tolower YEAR STATEFIP STATENAME RACE COFIPS    BIRTHS_RES  ATTHOSPITAL_RES POPF_FIXED POP_FIXED IM_RES_FIXED 
g hosprate=atthospital_res/births_res
g brate=births_res/(popf_fixed/1000)
g imr=im_res_fixed/(births_res/1000)
recode race (1=0)(2=1), gen(black)
rename cofips fips
rename popf_fixed fpop
rename pop_fixed totpop
keep year south statefip  fips black brate imr hosprate fpop totpop  

cd "C:\Users\ot3\Documents\CRFertility"
save frate_working_county, replace

 

 